package algorithm;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by User on 2017/9/11.
 */
public class PrimeAlgorithm {
    public static List factor(long g) {
        List result = new ArrayList(16);
        for (long i = 2; g != 1; i++)
            if (g % i == 0) {
                g /= i;
                result.add(i);
                i--; // i--使得i的值不变,即能把含有的所有的当前质因数， 如 2，除尽后， 再去除下一个指数， 如 3
            }

        return result;
    }

    public static void main(String[] args) {
        List factor = PrimeAlgorithm.factor(2132123);
        System.out.println(factor);
    }
}
